package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.Member;
import com.atguigu.crowd.entity.Project;
import com.atguigu.crowd.entity.ProjectManger;
import com.atguigu.crowd.mapper.ProjectMapper;
import com.atguigu.crowd.service.api.AuthProjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("")
public class AuthProjectServiceImpl implements AuthProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public PageInfo<Project> getAuthProjectPageInfo(String keyword, Integer pageNum, Integer pageSize) {
       //1.调用PageHelper的静态方法开启分页功能
        //体现了PageHelper的非侵入式设计 原本要做的查询不必要做任何修改
        PageHelper.startPage(pageNum,pageSize);

        //2.执行查询
        List<Project> list = projectMapper.selectProjectByKeyword(keyword);

//        System.out.println("查询到的list: "+list.toString());
        //3.封装到PageInfo对象中
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<Project> getProjectPageInfoForProjectManger(String keyword, Integer pageNum, Integer pageSize) {
        //1.调用PageHelper的静态方法开启分页功能
        //体现了PageHelper的非侵入式设计 原本要做的查询不必要做任何修改
        PageHelper.startPage(pageNum,pageSize);

        //2.执行查询
        List<Project> list = projectMapper.selectProjectByKeywordForProjectManger(keyword);
        System.out.println("查询到的 "+list);

//        System.out.println("查询到的list: "+list.toString());
        //3.封装到PageInfo对象中
        return new PageInfo<>(list);
    }


    //审核通过 修改pass字段
    @Override
    public void updateProjectPass(Integer projectId) {
        projectMapper.updatePassByProjectId(projectId);
    }

    //审核未通过
    @Override
    public void updateProjectNotPass(Integer projectId) {
       projectMapper.updateNotPassByProjectId(projectId);
    }

    //获取项目经理总数
    @Override
    public int getCountProjectMangeer() {
        return projectMapper.getCountManger();
    }



    //获取项目经理Id对应的count
    @Override
    public ProjectManger getMangerCount(Integer mangerId) {

        return projectMapper.getNumProjectByManger(mangerId);
    }

    @Override
    public void updateProjectManger(Integer projectId, String mangerName) {
        projectMapper.updateProjectForManger(projectId,mangerName);
    }

    @Override
    public void updateMangerCount(int mangerId, int count) {
            projectMapper.updateMangerCount(mangerId,count);
    }

    //设置项目中才开始的时间
    @Override
    public void updateProjectDeploydate(Integer projectId, String deploydate,String developmentStartDate) {
        projectMapper.updateProjectDeploy(projectId,deploydate,developmentStartDate);
    }


}
